package com.fmy.jurisdiction.core.commons.kits;

import com.fmy.jurisdiction.config.security.service.UserDetailsEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author Mr.fmy
 * @version 1.0.0
 * @ClassName SecurityKit
 * @Description TODO Security工具类
 * @createTime 2019/9/16 19:19
 */
public class SecurityKit {

    public static UserDetailsEntity get() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null) {
            return (UserDetailsEntity) authentication.getPrincipal();
        }
        return null;
    }

    public static Integer getId() {
        UserDetailsEntity user = get();
        return user != null ? user.getId() : null;
    }

    public static Integer getDeptId(){
        UserDetailsEntity user = get();
        return user != null ? user.getDeptId() : null;
    }
}
